//
//  CityViewController.m
//  LNA
//
//  Created by dllo on 16/1/28.
//  Copyright © 2016年 www.lanou3g.com蓝鸥. All rights reserved.
//

#import "CityViewController.h"
#import <AFNetworking.h>
#import <UIImageView+WebCache.h>
#import "MyLoopsView.h"
@interface CityViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic, retain) NSMutableArray *picArr;//轮播图数组
@property (nonatomic, retain) NSMutableArray *dataArr;
// 城市详情数组
@property (nonatomic, retain) UITableView *tableView;

@end

@implementation CityViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
#pragma mark - 创建tableview
    self.tableView =  [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    
    [self.view addSubview:_tableView];
    [_tableView release];
     // 重用池
    [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
  
    // 创建一个tableviewheader
    UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 200)];
    _tableView.tableHeaderView = headView;
    [headView release];
    
    // 获取数据
    [self data];
}
#pragma mark - 获取数据
- (void)data
{
    NSString *str =[NSString stringWithFormat:@"http:open.qyer.com/qyer/footprint/city_detail?city_id=%@",self.str];
    NSLog(@" str : %@",self.str);
   NSString *url =  @"&client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=20&lat=38.88250754987822&lon=121.5399249782786&page=1&track_app_channel=App%2520Store&track_app_version=6.8.3&track_device_info=iPhone7%2C2&track_deviceid=0C79B4F1-2C09-4E9A-805E-05836431AB22&track_os=ios%25209.2&v=1";
    AFHTTPSessionManager *sessionManager = [AFHTTPSessionManager manager];
    [sessionManager GET:[NSString stringWithFormat:@"%@%@",str,url] parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
//        NSLog(@"%lld",downloadProgress.totalUnitCount);
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        // 获取轮播图数据
        // 判断 如果轮播图 图片少于3的时候
        if ([responseObject[@"data"][@"photos"] count] < 3) {
            UIImageView *backimg = [[UIImageView alloc]initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, 200)];
            UILabel *lll = [[UILabel alloc]initWithFrame:CGRectMake(150, 20, self.view.frame.size.width - 150, 20)];
            lll.text = @"居然没图片";
            lll.textColor = [UIColor whiteColor];
            [backimg addSubview:lll];
            backimg.image = [UIImage imageNamed:@"boom.jpg"];
            [self.view addSubview:backimg];
            [backimg release];
            [lll release];
        }else{

        self.picArr = responseObject[@"data"][@"photos"];
        MyLoopsView *scroll = [MyLoopsView myLoopsViewWithFrame:CGRectMake(0, 64, self.view.frame.size.width, 200) imageArr:_picArr];
        // 超值自由行tableview
//            self.dataArr = responseObject[@"data"][@""]
        [self.view addSubview:scroll];
        }
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
//        NSLog(@"%@",error);
    }];
    
    
    
}
#pragma mark - tableview的方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    return 10;
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    
    return cell;
    
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
